package org.xuyuji.study.spring_jdbctemplate_demo;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.xuyuji.study.spring_jdbctemplate_demo.dao.IUserDao;
import org.xuyuji.study.spring_jdbctemplate_demo.model.UserModel;
import org.xuyuji.study.spring_jdbctemplate_demo.service.TradeService;

public class Main {
	private static final Logger logger = Logger.getLogger(Main.class);
	
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		IUserDao userDao = (IUserDao) ctx.getBean("userDao");
		TradeService trade = (TradeService) ctx.getBean("trade");
		
		UserModel seller = new UserModel();
		seller.setUsername("张三");
		int sellerId = userDao.save(seller);
		
		seller.setId(sellerId);
		seller.setMoney(10);
		userDao.modify(seller);
		
		UserModel buyer = new UserModel();
		buyer.setUsername("李四");
		int buyerId = userDao.save(buyer);
		
		buyer.setId(buyerId);
		buyer.setMoney(10);
		userDao.modify(buyer);
		
		logger.info("卖方:" + seller);
		logger.info("买方:" + buyer);
		trade.trade(seller, buyer, 5);
		logger.info("卖方:" + seller);
		logger.info("买方:" + buyer);
		
		userDao.delete(sellerId);
		userDao.delete(buyerId);
		
		System.out.println(userDao.load(1));
	}
}
